

package cn.shengchao.examstar.product.ohs.local.message;

import cn.shengchao.examstar.product.domain.entity.Course;
import cn.shengchao.examstar.product.domain.entity.CourseKnowledgeNode;
import cn.shengchao.examstar.product.domain.entity.Teacher;
import lombok.Data;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
public class CourseListDto {

    private Long id;
    //名称
    private String name;
    //图片
    private String imgUrl;
    private String cardUrl;
    private BigDecimal price;
    private Integer courseType;
    //课程知识点数量
    private Long knowledgeNodeNum;
    private Long unLockKnowledgeNodeNum = 0L;
    private Double classHour;
    //课程评分
    private Double score;
    //描述
    private String description;
    //是否收藏
    private Boolean collect;
    //教师描述
    @Setter
    private List<Teacher> teacher;

    private List<CourseKnowledgeNode> knowledgeNodes;

    public static CourseListDto of(Course course) {
        CourseListDto courseListDto = new CourseListDto();
        courseListDto.setId(course.getId());
        courseListDto.setName(course.getName().getValue());
        courseListDto.setCardUrl(course.getCardUrl());
        courseListDto.setImgUrl(course.getImageUrl());
        courseListDto.setCourseType(course.getCourseType());
        courseListDto.setPrice(course.getPrice().getPrice());
        courseListDto.setScore(course.getScore());
        courseListDto.setDescription(course.getDescription());
        if (course.getKnowledgeNodes() == null) {
            courseListDto.setKnowledgeNodes(new ArrayList<>());
        } else {
            courseListDto.setKnowledgeNodes(course.getKnowledgeNodes());
        }
        courseListDto.setClassHour(course.getClassHour());
        return courseListDto;
    }

}
